package main

import (
	"encoding/json"
	"io/ioutil"
	"os"
)

const BackupConfigFileName = "./configs/accesscenterd.json"

type Config struct {
	HttpsPort  int
	DBUrl      string
	DBName     string
	DBUser     string //数据库用户名
	DBPwd      string //数据库密码
	HTTPS      bool   //HTTPS: true false
	KeyFile    string
	CertFile   string
	IPQueryUrl string
	Key        int64
}

func loadConfig(file string) (*Config, error) {
	if file == "" {
		file = os.Args[0] + ".json"
	}
	if _, err := os.Stat(file); os.IsNotExist(err) {
		file = BackupConfigFileName
	}
	buf, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}

	var cfg Config
	err = json.Unmarshal(buf, &cfg)

	return &cfg, err
}
